package com.zretc.controller;

import com.github.pagehelper.PageInfo;
import com.zretc.entity.Film;
import com.zretc.entity.FilmRank;
import com.zretc.service.FilmRankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/back")
public class BackFilmRankController {

    @Autowired
    private FilmRankService filmRankService;

    @GetMapping("/filmRankList")
    @ResponseBody
    public PageInfo<FilmRank> getFilmRankByCondition(@RequestParam("page") String pageNum,
                                                     @RequestParam("limit") String pageSize,
                                                     String filmName,
                                                     String filmReleaseTime) {
        Map<String, String> map = new HashMap<>();
        map.put("pageNum",pageNum);
        map.put("pageSize",pageSize);
        map.put("filmName",filmName);
        map.put("filmReleaseTime",filmReleaseTime);
        PageInfo<FilmRank> filmRankPageInfo = filmRankService.getFilmRankByCondition(map);

        return filmRankPageInfo;
    }

    @PutMapping("/updateFilmRankNumber")
    @ResponseBody
    public boolean updateFilmRankByFilmRankId(@RequestParam("filmId") String filmId,
                                              @RequestParam("rankNumber") String rankNumber) {

        FilmRank filmRank = new FilmRank();

        Film film = new Film();
        film.setFilmId(Integer.valueOf(filmId));
        filmRank.setFilm(film);
        filmRank.setRankNumber(Integer.valueOf(rankNumber));

        boolean b = filmRankService.updateFilmRankByFilmRankId(filmRank);
        if (b == true) {
            return true;
        } else {
            return false;
        }
    }

}
